home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
- /* zap.c - version 1.0.3 */
-
- #include "hack.h"
-
- extern struct obj *mkobj_at();
- extern struct monst *makemon(), *mkmon_at(), youmonst;
- extern char *exclam();
-
- extern char *fl[];
-
- /* bhit: called when a weapon is thrown (sym = obj->olet) or when an
- IMMEDIATE wand is zapped (sym = 0); the weapon falls down at end of
- range or when a monster is hit; the monster is returned, and bhitpos
- is set to the final position of the weapon thrown; the ray of a wand
- may affect several objects and monsters on its path - for each of
- these an argument function is called. */
- /* check !u.uswallow before calling bhit() */
-
- struct monst *
- bhit(ddx,ddy,range,sym,fhitm,fhito,obj)
- register int ddx,ddy,range; /* direction and range */
- char sym; /* symbol displayed on path */
- int (*fhitm)(), (*fhito)(); /* fns called when mon/obj hit */
- struct obj *obj; /* 2nd arg to fhitm/fhito */
- {
- register struct monst *mtmp;
- register struct obj *otmp;
- register int typ;
-
- bhitpos.x = u.ux;
- bhitpos.y = u.uy;
-
- if(sym) tmp_at(-1, sym); /* open call */
- while(range-- > 0) {
- bhitpos.x += ddx;
- bhitpos.y += ddy;
- typ = levl[bhitpos.x][bhitpos.y].typ;
- if(mtmp = m_at(bhitpos.x,bhitpos.y)){
- if(sym) {
- tmp_at(-1, -1); /* close call */
- return(mtmp);
- }
- (*fhitm)(mtmp, obj);
- range -= 3;
- }
- if(fhito && (otmp = o_at(bhitpos.x,bhitpos.y))){
- if((*fhito)(otmp, obj))
- range--;
- }
- if(!ZAP_POS(typ)) {
- bhitpos.x -= ddx;
- bhitpos.y -= ddy;
- break;
- }
- if(sym) tmp_at(bhitpos.x, bhitpos.y);
- }
-
- /* leave last symbol unless in a pool */
- if(sym)
- tmp_at(-1, (levl[bhitpos.x][bhitpos.y].typ == POOL) ? -1 : 0);
- return(0);
- }
-
- struct monst *
- boomhit(dx,dy) {
- register int i, ct;
- register struct monst *mtmp;
- char sym = ')';
- extern schar xdir[], ydir[];
-
- bhitpos.x = u.ux;
- bhitpos.y = u.uy;
-
- for(i=0; i<8; i++) if(xdir[i] == dx && ydir[i] == dy) break;
- tmp_at(-1, sym); /* open call */
- for(ct=0; ct<10; ct++) {
- if(i == 8) i = 0;
- sym = ')' + '(' - sym;
- tmp_at(-2, sym); /* change let call */
- dx = xdir[i];
- dy = ydir[i];
- bhitpos.x += dx;
- bhitpos.y += dy;
- if(mtmp = m_at(bhitpos.x, bhitpos.y)){
- tmp_at(-1,-1);
- return(mtmp);
- }
- if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)) {
- bhitpos.x -= dx;
- bhitpos.y -= dy;
- break;
- }
- if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
- if(rn2(20) >= 10+u.ulevel){ /* we hit ourselves */
- (void) thitu(10, rnd(10), "boomerang");
- break;
- } else { /* we catch it */
- tmp_at(-1,-1);
- pline("Skillfully, you catch the boomerang.");
- return(&youmonst);
- }
- }
- tmp_at(bhitpos.x, bhitpos.y);
- if(ct % 5 != 0) i++;
- }
- tmp_at(-1, -1); /* do not leave last symbol */
- return(0);
- }
-
- char
- dirlet(dx,dy) register dx,dy; {
- return
- (dx == dy) ? '\\' : (dx && dy) ? '/' : dx ? '-' : '|';
- }
-